package com.gitee.yunduansing.authcommon.model.common;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 返回模型
 */
@Data
@ApiModel(description = "全局API返回的泛型类")
public class ResponseModel<T> implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "状态码，成功为200，错误为500",example = "200")
    private int status;
    @ApiModelProperty(value = "成功或失败，成功为true，错误为false",example = "true")
    private boolean success;
    @ApiModelProperty(value = "提示信息")
    private String msg;
    @ApiModelProperty(value = "返回的数据")
    private T data;

    public ResponseModel(int s,boolean ss,String m,T d){
        this.status=s;
        this.success=ss;
        this.msg=m;
        this.data=d;
    }

    /**
     * 返回200，success=true
     * @return
     */
    public static ResponseModel ok(){
        return new ResponseModel(200,true,"",null);
    }

    /**
     * 返回200，success=true
     * @param data 需要返回的数据
     * @return
     */
    public static <T> ResponseModel ok(T data){
        return new ResponseModel(200,true,"",data);
    }

    /**
     * 返回200，success=true
     * @param data 需要返回的数据
     * @param msg 返回的提示文本
     * @return
     */
    public static <T> ResponseModel ok(T data,String msg){
        return new ResponseModel(200,true,msg,data);
    }

    /**
     * 返回500，success=false
     * @param msg 返回的错误提示
     * @return
     */
    public static ResponseModel error(String msg){
        return new ResponseModel(500,false,msg,null);
    }

    /**
     * 
     * @param status
     * @param msg
     * @return
     */
    public static ResponseModel error(int status,String msg){
        return new ResponseModel(status,false,msg,null);
    }

    /**
     * 返回500，success=false
     * @param data 返回的数据
     * @param msg 返回的错误提示
     * @return
     */
    public static <T> ResponseModel error(T data,String msg){
        return new ResponseModel(500,false,msg,data);
    }

    /**
     * 返回status，success=false
     * @param status
     * @param data
     * @param msg
     * @return
     */
    public static <T> ResponseModel error(int status,T data,String msg){
        return new ResponseModel(status,false,msg,data);
    }
}
